package com.ruoyi.controller.fanruan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.jpjs.common.fanruan.QwFirst;
import com.ruoyi.service.fanruan.IQwFirstService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 全屋门窗Controller
 *
 * @author ruoyi
 * @date 2020-11-04
 */
@Controller
@RequestMapping("/fanruan/qw")
public class QwFirstController extends BaseController
{
    private String prefix = "fanruan/qw";

    @Autowired
    private IQwFirstService qwFirstService;

    @RequiresPermissions("fanruan:qw:view")
    @GetMapping()
    public String qw()
    {
        return "fanruan/qw/qw";
    }

    /**
     * 查询全屋门窗列表
     */
    @RequiresPermissions("fanruan:qw:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QwFirst qwFirst)
    {
        startPage();
        List<QwFirst> list = qwFirstService.selectQwFirstList(qwFirst);
        return getDataTable(list);
    }

    /**
     * 导出全屋门窗列表
     */
    @RequiresPermissions("fanruan:qw:export")
    @Log(title = "全屋门窗", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QwFirst qwFirst)
    {
        List<QwFirst> list = qwFirstService.selectQwFirstList(qwFirst);
        ExcelUtil<QwFirst> util = new ExcelUtil<QwFirst>(QwFirst.class);
        return util.exportExcel(list, "qw");
    }

    /**
     * 新增全屋门窗
     */
    @GetMapping("/add")
    public String add()
    {
        return "fanruan/qw/add";
    }

    /**
     * 新增保存全屋门窗
     */
    @RequiresPermissions("fanruan:qw:add")
    @Log(title = "全屋门窗", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QwFirst qwFirst)
    {
        return toAjax(qwFirstService.insertQwFirst(qwFirst));
    }

    /**
     * 修改全屋门窗
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        QwFirst qwFirst = qwFirstService.selectQwFirstById(id);
        mmap.put("qwFirst", qwFirst);
        return "fanruan/qw/edit";
    }

    /**
     * 修改保存全屋门窗
     */
    @RequiresPermissions("fanruan:qw:edit")
    @Log(title = "全屋门窗", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QwFirst qwFirst)
    {
        return toAjax(qwFirstService.updateQwFirst(qwFirst));
    }

    /**
     * 删除全屋门窗
     */
    @RequiresPermissions("fanruan:qw:remove")
    @Log(title = "全屋门窗", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qwFirstService.deleteQwFirstByIds(ids));
    }
}
